//
//  TBRTextMineController.m
//  TBRentClient
//
//  Created by tonbright on 2018/4/18.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "TBRTextMineController.h"
#import "UIColor+Hex.h"
#import "BaseInformationView.h"

@interface TBRTextMineController ()<UITableViewDataSource, UITableViewDelegate,BaseInformationViewDelegate>
@property (nonatomic, strong) UIView *topBgView;
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation TBRTextMineController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self ISG_NavigationBarRightBarWithTitle:@"设置" andAction:@selector(setBtnClick)];
    [self loadData];
    [self setupUI];
}

- (void)loadData {
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.subviews[0].alpha = 0;

}

- (void)setupUI {
    [self setupNavItem];
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView = tableView;
    [self.view addSubview:tableView];
    [self.tableView makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.leading.trailing.offset(0);
        make.top.offset(-64);
    }];
    
    tableView.backgroundColor = [UIColor lightGrayColor];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.showsVerticalScrollIndicator = NO;
    tableView.separatorColor = [UIColor lightGrayColor];
    tableView.estimatedRowHeight = 0;
    tableView.estimatedSectionHeaderHeight = 0;
    tableView.estimatedSectionFooterHeight = 0;
    [tableView addSubview:self.topBgView];
    
}

- (void)setupNavItem {
    [self ISG_NavigationBarWithBackButtonTitle:@"回退" leftImageNamed:@"" andAction:@selector(setBtnClick)];
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 130;
    }
    return CGFLOAT_MIN;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        BaseInformationView *view = [[BaseInformationView alloc] initWithFrame:CGRectMake(0, 0, Width, 130)];
        view.delegate = self;
//        view.userInfo = [ISGUserInfo sharedUserInfo];
        return view;
    }
    return nil;
}

- (UIView *)topBgView {
    if (!_topBgView) {
        _topBgView = [[UIView alloc] initWithFrame:CGRectMake(0, -64, Width, 0)];
        _topBgView.backgroundColor = cCommonRedColor;
    }
    return _topBgView;
}


#pragma mark - 实现数据源方法
#pragma mark - 返回组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

#pragma mark - 返回行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 30;
}

#pragma mark - 返回每行内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //自定义cell
    
    NSString *tableViewCellId = @"tableViewCellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableViewCellId];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableViewCellId];
        cell.textLabel.text = @"我是测试数据额";
    }
    
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"<#XibClass#>Id" forIndexPath:indexPath];
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.goodsModel = self.allGoodsArray[indexPath.row];
    //设置数据
    //返回
    return cell;
}



#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"*********%.f",self.tableView.contentOffset.y);
    if (self.tableView.contentOffset.y > 64) {
        self.titleText = @"我的";
        self.navigationController.navigationBar.subviews[0].alpha = 1;

    } else {
        self.titleText = @"";
        self.navigationController.navigationBar.subviews[0].alpha = 0;
    }
    if (self.tableView.contentOffset.y<0) {
        CGRect rect = _topBgView.frame;
        rect.origin.y = self.tableView.contentOffset.y;
        rect.size.height = -self.tableView.contentOffset.y;
        _topBgView.frame = rect;
    }
}

- (void)setBtnClick {
    UIViewController *c = [UIViewController new];
    c.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController pushViewController:c animated:YES];
}

@end
